# Project: Acess
# Common Code

CC = gcc
AS = nasm
RM = @rm -f
LD = ld
OBJDUMP = objdump
MAKEDEP = gcc -M

BIN = "../AcessOS.bin"
AOBJ = start.ao assembler.ao user.ao
# Kernel Core
COBJ = main.o desctab.o proc.o mm2.o vm8086.o
# Auxilary
COBJ += system.o heap.o lib.o irq.o time.o syscalls.o scrn.o debug.o config.o edi.o module2.o drvlib.o
# Filesystem
COBJ += vfs.o fs/devfs2.o fs/internal.o fs/rom.o fs/fat.o fs/ext2.o
# Binary
COBJ += binload.o bin/elf.o bin/pe.o
# Core Drivers
COBJ += dma.o drv/pci.o drv/proc.o
# Drivers
COBJ += drv/ide.o drv/fdd.o drv/kb.o drv/tty.o drv/fifo.o

INCS = -I./include
CPPFLAGS = $(INCS)
CFLAGS = -Wall -O -fstrength-reduce -fleading-underscore -fno-stack-protector -nostdinc -fno-builtin $(CPPFLAGS)
ASFLAGS = -f elf32
LDFLAGS = -T link.ld

.PHONY : all clean

all: $(BIN)

clean:
	$(RM) $(BIN) $(AOBJ) $(COBJ)

$(BIN): $(AOBJ) $(COBJ)
	@echo --- Linking ---
	@$(LD) $(LDFLAGS) -o $@ $?
	@$(OBJDUMP) -d -S $@ > ../AcessOS.dsm
	@$(OBJDUMP) -x $@ > ../AcessOS.dmp

$(COBJ): %.o: %.c
	@echo === GCC -c $< -o $@
	@$(MAKEDEP) $(CPPFLAGS) -o .deps/$*.d $<
	@$(CC) $(CFLAGS) -c $< -o $@

$(AOBJ): %.ao: %.asm
	@echo === NASM $< -o $@
	@$(AS) $(ASFLAGS) $< -o $@

-include $(OBJ:%.o=.deps/%.c.P)

assembler.ao: commonasm.inc.asm
